// Strict Mode SVN
"use strict";

var Form = {

	// CSS Valid Class
	validClass : 'valid',

	// First Name
	fName : {
		minLength : 1,
		maxLength : 15,
		fieldName : 'First Name'
	},

	// Last Name
	lName : {
		minLength : 1,
		maxLength : 15,
		fieldName : 'Last Name'
	},

	// Validate Length
	validateLength : function(formEl, type) {
		if(formEl.value.length > type.maxLength || formEl.value.length < type.minLength) {
			formEl.className = formEl.className.replace(' ' + Form.validClass, '');
			return false;
		} else {
			if(formEl.className.indexOf(' ' + Form.validClass) === -1)
            {
                formEl.className += ' ' + Form.validClass;
                return true;
            }
		}
	},


	// Validate E-Mail
	validateEmail : function(formEl) {
		var regEx = /^([0-9a-zA-Z]([\-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][\-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
		var emailTest = regEx.test(formEl.value);

		if(emailTest) {
			if(formEl.className.indexOf(' ' + Form.validClass) === -1)
            {
                formEl.className += Form.validClass;
                return true;
            }
		} else {
			formEl.className = formEl.className.replace(' ' + Form.validClass, '');
			return false;
		}
	},

	// Get Submit
	getSubmit : function(formID) {
		var inputs = document.getElementById(formID).getElementsByTagName('input');
		for(var i = 0; i < inputs.length; i++) {
			if(inputs[i].type === 'submit') {
				return inputs[i];
			}
		}
		return false;
	}
};
